/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "common/common.h"

namespace ArkUICapiTest {

static napi_value TestScrollScrollSnap001(napi_env env, napi_callback_info info)
{
    NAPI_START(scroll, ARKUI_NODE_SCROLL);
    float param = 1.0;
    float paramSecond = SIZE_100;
    ArkUI_NumberValue value[] = {
        {.i32 = ARKUI_SCROLL_SNAP_ALIGN_NONE}, {.i32 = true}, {.i32 = true}, {.f32 = param}, {.f32 = paramSecond}};
    ArkUI_AttributeItem value_item = {value, sizeof(value) / sizeof(ArkUI_NumberValue)};
    auto ret = nodeAPI->setAttribute(scroll, NODE_SCROLL_SNAP, &value_item);
    ASSERT_EQ(ret, SUCCESS);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_0].i32, ARKUI_SCROLL_SNAP_ALIGN_NONE);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_1].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_2].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_3].f32, param);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_4].f32, paramSecond);
    NAPI_END;
}

static napi_value TestScrollScrollSnap002(napi_env env, napi_callback_info info)
{
    NAPI_START(scroll, ARKUI_NODE_SCROLL);
    float param = 1.0;
    float paramSecond = SIZE_100;
    ArkUI_NumberValue value[] = {
        {.i32 = ARKUI_SCROLL_SNAP_ALIGN_START}, {.i32 = true}, {.i32 = true}, {.f32 = param}, {.f32 = paramSecond}};
    ArkUI_AttributeItem value_item = {value, sizeof(value) / sizeof(ArkUI_NumberValue)};
    auto ret = nodeAPI->setAttribute(scroll, NODE_SCROLL_SNAP, &value_item);
    ASSERT_EQ(ret, SUCCESS);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_0].i32, ARKUI_SCROLL_SNAP_ALIGN_START);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_1].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_2].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_3].f32, param);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_4].f32, paramSecond);
    NAPI_END;
}

static napi_value TestScrollScrollSnap003(napi_env env, napi_callback_info info)
{
    NAPI_START(scroll, ARKUI_NODE_SCROLL);
    float param = 1.0;
    float paramSecond = SIZE_100;
    ArkUI_NumberValue value[] = {
        {.i32 = ARKUI_SCROLL_SNAP_ALIGN_CENTER}, {.i32 = true}, {.i32 = true}, {.f32 = param}, {.f32 = paramSecond}};
    ArkUI_AttributeItem value_item = {value, sizeof(value) / sizeof(ArkUI_NumberValue)};
    auto ret = nodeAPI->setAttribute(scroll, NODE_SCROLL_SNAP, &value_item);
    ASSERT_EQ(ret, SUCCESS);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_0].i32, ARKUI_SCROLL_SNAP_ALIGN_CENTER);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_1].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_2].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_3].f32, param);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_4].f32, paramSecond);
    NAPI_END;
}

static napi_value TestScrollScrollSnap004(napi_env env, napi_callback_info info)
{
    NAPI_START(scroll, ARKUI_NODE_SCROLL);
    float param = 1.0;
    float paramSecond = SIZE_100;
    ArkUI_NumberValue value[] = {
        {.i32 = ARKUI_SCROLL_SNAP_ALIGN_END}, {.i32 = true}, {.i32 = true}, {.f32 = param}, {.f32 = paramSecond}};
    ArkUI_AttributeItem value_item = {value, sizeof(value) / sizeof(ArkUI_NumberValue)};
    auto ret = nodeAPI->setAttribute(scroll, NODE_SCROLL_SNAP, &value_item);
    ASSERT_EQ(ret, SUCCESS);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_0].i32, ARKUI_SCROLL_SNAP_ALIGN_END);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_1].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_2].i32, true);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_3].f32, param);
    ASSERT_EQ(nodeAPI->getAttribute(scroll, NODE_SCROLL_SNAP)->value[PARAM_4].f32, paramSecond);
    NAPI_END;
}
} // namespace ArkUICapiTest
